import { createRouter,createWebHashHistory } from 'vue-router'
// import Layout from '../components/HelloWorld.vue'
import { staticRouter } from './modules/staticRouter'
import { dynamicRouter } from './modules/dynamicRouter'
import useUserStore from "@/stores/modules/user";
const router = createRouter({
    history: createWebHashHistory(),
    routes: [...staticRouter,...dynamicRouter]
})
router.beforeEach((to, from, next) => {
    const userStore = useUserStore()
    // 登录页面且未登录。跳转到登录页
    if (to.path === '/login') return next();
    // 没有登录，重定向到登录页面
    if (!userStore.loginStatus) return next(`/login?redirect=${to.path}`);
    next();
})
export default router
